﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="recipeEdit.aspx.cs" Inherits="PeisongWeb.admin.recipeEdit" %>

<%@ Register TagName="menu" Src="controls/menu.ascx" TagPrefix="uc2" %>
<%@ Register TagName="top" Src="controls/top.ascx" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>菜谱编辑 - 想购网长期采购物流配送系统</title>
    <!--#include file="style.inc"-->

    <script src="/app_common/scripts/jquery-latest.pack.js" type="text/javascript"></script>

    <script src="/app_common/scripts/json-minified.js" type="text/javascript"></script>

    <script src="/app_common/scripts/QueryString.js" type="text/javascript"></script>

    <script type="text/javascript">
        function selectAll(obj) {
            $(':checkbox', $('#tb_pro')).attr('checked', $(obj).attr('checked') ? true : null);
        }
        // 判断选择的是否存在重复的数据
        function ValidateDuplicate() {
            var msg = '';
            var checkboxes = $(':checkbox[checked]', $('#tb_pro'));
            if ($G('category').length != 0) {
            } else {
            }
            if (checkboxes.length != 0) {
                $(checkboxes).each(function(entryIndex, entry) {
                    var productId = $(entry).parent().attr('ProductId');
                    if (isExistsProduct(productId)) {
                        msg += $(entry).parent().attr('Name') + '\r\n';
                    }
                });
                if (msg.length != 0) {
                    return confirm('您当前选择的原料有重复项：\r\n' + msg + '是否忽略重复项继续添加，还是取消添加?');
                }
            } else {
                alert('未选择任何原料！');
                return false;
            }
        }
        function isExistsProduct(productId) {
            var isExists = false;
            var current = $('#hdProductSotre').val();
            if (current.length != 0) {

                var jsonArray = jsonParse(current);
                for (var i = 0; i < jsonArray.length; i++) {
                    if (jsonArray[i]["ProductId"] == productId) {
                        isExists = true;
                        break;
                    }
                }
            }
            return isExists;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm1" runat="server" OnAsyncPostBackError="sm1_AsyncPostBackError">
    </asp:ScriptManager>
    <ext:ScriptManager ID="ScriptManager1" runat="server" />
    <uc1:top ID="Top1" runat="server" />
    <uc2:menu ID="Menu1" runat="server" />
    <div id="admin_main" style="margin: 10px 0 0 10px;">
        <ext:Panel ID="panel_Title" runat="server" Title="菜谱编辑" BodyStyle="padding:5px 5px 0"
            Width="650" Frame="true" ButtonAlign="Center">
            <Body>
                <ext:Panel ID="Panel3" runat="server">
                    <Body>
                        <ext:ColumnLayout ID="ColumnLayout1" runat="server">
                            <ext:LayoutColumn ColumnWidth=".5">
                                <ext:Panel ID="Panel4" runat="server" Border="false" Header="false">
                                    <Body>
                                        <div id="admin_edit_content">
                                            <ul>
                                                <li>
                                                    <label>
                                                        菜谱名称 *</label>
                                                    <asp:TextBox runat="server" ID="txt_Name" Width="250"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="请输入菜谱名称"
                                                        ControlToValidate="txt_Name" Display="Dynamic"></asp:RequiredFieldValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        所属类别 *</label>
                                                    <asp:DropDownList ID="drp_ParentCategory" runat="server" DataTextField="name" DataValueField="rcid">
                                                    </asp:DropDownList>
                                                    <asp:RequiredFieldValidator runat="server" ID="recipeCategory" ErrorMessage="请选择菜谱类别"
                                                        ControlToValidate="drp_ParentCategory" Display="Dynamic" InitialValue="0"></asp:RequiredFieldValidator>
                                                </li>
                                            </ul>
                                            <br />
                                            <p>
                                                <table width="98%" border="0" cellpadding="4" cellspacing="1">
                                                    <tr>
                                                        <td>
                                                            <h2 style="float: left; margin-right: 20px">
                                                                原料信息</h2>
                                                            <span style="<%=power>=2?"": "display:none" %>">
                                                                <asp:LinkButton runat="server" ID="lbn_AddProduct" Text="添加原料" OnCommand="lbn_AddProduct_Click"
                                                                    CausesValidation="false"></asp:LinkButton>
                                                            </span>
                                                            <hr />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <div id="admin_edit_content_infor" style="width: 630px">
                                                                <table width="98%">
                                                                    <tr align="center" style="height: 20px;">
                                                                        <td width="20%" bgcolor="#C0D5F0">
                                                                            序号
                                                                        </td>
                                                                        <td width="60%" bgcolor="#C0D5F0">
                                                                            商品名称
                                                                        </td>
                                                                        <td width="20%" bgcolor="#C0D5F0" style="<%=power>=2?"": "display:none" %>">
                                                                            删除
                                                                        </td>
                                                                    </tr>
                                                                    <asp:Repeater runat="server" ID="rptSelectedProduct" OnItemCommand="rptSelectedProduct_ItemCommand">
                                                                        <ItemTemplate>
                                                                            <tr align="center" style="height: 20px;">
                                                                                <td bgcolor="#FFFFFF">
                                                                                    <%#Container.ItemIndex+1 %>
                                                                                    <asp:HiddenField runat="server" ID="hdProductId" Value='<%#Eval("ProductId") %>' />
                                                                                </td>
                                                                                <td bgcolor="#FFFFFF">
                                                                                    <%#Eval("ProductName")%>
                                                                                </td>
                                                                                <td bgcolor="#FFFFFF" style="<%=power>=2?"": "display:none" %>">
                                                                                    <asp:LinkButton runat="server" ID="link_SelectedProduct_Del" CausesValidation="false"
                                                                                        CommandArgument='<%#Eval("ProductId") %>' CommandName="Del" Text="删除"></asp:LinkButton>
                                                                                </td>
                                                                            </tr>
                                                                        </ItemTemplate>
                                                                    </asp:Repeater>
                                                                </table>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </p>
                                            <br />
                                            <ul>
                                                <li>
                                                    <label>
                                                        描述 *</label>
                                                    <ext:HtmlEditor runat="server" ID="txtDescrption">
                                                    </ext:HtmlEditor>
                                                </li>
                                                <li>
                                                    <label>
                                                        排序值 *</label>
                                                    <asp:TextBox runat="server" ID="txt_Sort"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="请输入排序值"
                                                        ControlToValidate="txt_Sort" Display="Dynamic"></asp:RequiredFieldValidator>
                                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txt_Sort"
                                                        Display="Dynamic" ErrorMessage="应为数字" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
                                                </li>
                                                <li>
                                                    <label>
                                                        是否显示</label>
                                                    <input runat="server" type="checkbox" id="chx_isShow" name="check1" checked="checked" />是
                                                </li>
                                                <li>
                                                    <label>
                                                        是否推荐</label>
                                                    <asp:CheckBox runat="server" ID="chkRecommend" />
                                                </li>
                                                <li>
                                                    <label>
                                                        &nbsp;
                                                    </label>
                                                    <span style="<%=power>=2?"": "display:none" %>">
                                                        <asp:Button runat="server" ID="btn_Save" Text="保 存" OnClick="btn_Save_Click" />
                                                    </span>
                                                    <input type="button" id="btn_Return" value="返 回" onclick="javascript:window.location='recipeList.aspx';" />
                                                </li>
                                            </ul>
                                        </div>
                                    </Body>
                                </ext:Panel>
                            </ext:LayoutColumn>
                        </ext:ColumnLayout>
                    </Body>
                </ext:Panel>
            </Body>
        </ext:Panel>
        <ext:Window ID="win_product" runat="server" Title="添加原料" Height="550px" Width="900px"
            BodyStyle="padding: 6px; background-color: #fff;" AutoScroll="true" Modal="True"
            Resizable="false" ShowOnLoad="false" Draggable="true" Icon="ApplicationViewDetail">
            <Body>
                <asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
                    <Triggers>
                        <asp:PostBackTrigger ControlID="lbn_AddTo" />
                    </Triggers>
                    <ContentTemplate>
                        <div class="details">
                            <table width="98%" border="0" cellpadding="4" cellspacing="1" style="text-align: left">
                                <tr>
                                    <td style="width: 18%;">
                                        <label style="line-height: 20px;">
                                            大 类：</label>
                                        <asp:DropDownList runat="server" ID="ddl_CategoryRoot" DataTextField="name" DataValueField="categoryId"
                                            AutoPostBack="True" OnSelectedIndexChanged="ddl_CategoryRoot_SelectedIndexChanged">
                                        </asp:DropDownList>
                                    </td>
                                    <td style="width: 18%">
                                        <label style="line-height: 20px;">
                                            小 类：</label>
                                        <asp:DropDownList runat="server" ID="ddl_CategorySub" DataTextField="name" DataValueField="categoryId">
                                        </asp:DropDownList>
                                    </td>
                                    <td style="width: 18%">
                                        商品编号:<asp:TextBox ID="txt_ProductNo" runat="server" Width="80px"></asp:TextBox>
                                    </td>
                                    <td style="width: 18%">
                                        商品名称:<asp:TextBox ID="txt_ProductName" runat="server" Width="80px"></asp:TextBox>
                                    </td>
                                    <td style="width: 16%">
                                        <asp:LinkButton ID="lbn_search" runat="server" Text="［搜索］" CausesValidation="false"
                                            OnClick="lbn_search_Click"></asp:LinkButton>
                                        <asp:LinkButton ID="lbn_reset" runat="server" Text="[重置]" CausesValidation="false"
                                            OnClick="lbn_reset_Click"></asp:LinkButton>
                                    </td>
                                    <td style="width: 16%">
                                        <asp:LinkButton ID="lbn_AddTo" runat="server" Text="[确认添加]" CausesValidation="false"
                                            OnClick="lbn_AddTo_Click" OnClientClick="return ValidateDuplicate();"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                            <table id="tb_pro" width="98%" border="0" cellpadding="4" cellspacing="1" bgcolor="#99BBE8"
                                style="text-align: left">
                                <asp:Repeater runat="server" ID="rpt_Products">
                                    <HeaderTemplate>
                                        <tr align="center" style="height: 20px;">
                                            <td width="20%" bgcolor="#C0D5F0">
                                                商品编号
                                            </td>
                                            <td width="50%" bgcolor="#C0D5F0">
                                                商品名称
                                            </td>
                                            <td width="30%" bgcolor="#C0D5F0">
                                                <input type="checkbox" name="checkedAll" id="checkedAll" onclick="selectAll(this)" />全选/取消
                                            </td>
                                        </tr>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr align="center" style="height: 20px;">
                                            <td bgcolor="#FFFFFF">
                                                <%# Eval("productNo")%>
                                            </td>
                                            <td bgcolor="#FFFFFF">
                                                <%# Eval("name")%>
                                            </td>
                                            <td bgcolor="#FFFFFF" align="center">
                                                <asp:CheckBox ID="cbx_isSelect" ProductId='<%#Eval("productId") %>' Name='<%#Eval("name") %>'
                                                    runat="server" />
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </table>
                            <div>
                                <webdiyer:AspNetPager ID="AspNetPager1" NumericButtonType="Text" MoreButtonType="Text"
                                    runat="server" AlwaysShow="False" PageSize="20" InvalidPageIndexErrorMessage="无效页码"
                                    PageIndexOutOfRangeErrorMessage="页码超出范围" ShowCustomInfoSection="Left" CustomInfoHTML=" 每页%PageSize%条记录 | 总共%RecordCount%条记录 "
                                    CustomInfoTextAlign="Left" HorizontalAlign="Right" OnPageChanged="AspNetPager1_PageChanged"
                                    NextPageText="下一页" FirstPageText="首页" LastPageText="末页" PrevPageText="上一页">
                                </webdiyer:AspNetPager>
                            </div>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </Body>
        </ext:Window>
    </div>
    <asp:HiddenField runat="server" ID="hdProductSotre" />
    <asp:HiddenField runat="server" ID="hdCurrentSource" />
    <asp:HiddenField runat="server" ID="hdCurrentDishName" />
    </form>
</body>
</html>
